package com.jy.wms.web;

import com.jy.wms.pojo.User;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sysuser")
public class SysUserController2 {
    @RequestMapping(value = "/user")
    public String toUser(){
        return "user/user";
    }
    @RequestMapping(value = "/addUser")
    public String addUser(){
        return "user/addUser";
    }
    @RequestMapping(value = "/userform")
    public @ResponseBody  String userform(@RequestBody User user){
        JSONObject jsonObject=JSONObject.fromObject(user);
        System.out.println(jsonObject.toString());
        return jsonObject.toString();
    }
    @RequestMapping(value = "/editUser")
    public String toEditUser(String id,Model model){

        model.addAttribute("id",id);
        return "user/editUser";
    }
    @RequestMapping(value = "/getEditUser")
    public @ResponseBody JSONObject getEditUser(String id){
//        Login user =new Login();
//
//        user.setUserAccount("山东济南");
//        user.setAppCode("zxbzwms");
//        user.setUserPassword("123123");
//        JSONObject jsonuser=new JSONObject();
//        jsonuser.accumulate("user",user);
        User user=new User();
        user.setAddress("123123");
        user.setAppCode("sswms");
        //不同文本框
        user.setUserAccount("zzp你");
        //select
        user.setAppId(1);
        //异步加载select
        user.setEmpLevel(3);
        //备注
        user.setColleage("hahahahhahaha");
        //radio
        user.setType(1);
        //checkbox
        user.setGender("1,2");
        /*select2多选*/
        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.accumulate("id","1cb83591663547e1b2a1f2b684a378f3");
        jsonObject2.accumulate("text","小静测试001");


        JSONArray jsonArray = new JSONArray();
        jsonArray.add(jsonObject2);
        /*select2单选*/
        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.accumulate("id","d554124ed0c44e02a8f12ea17586f989");
        jsonObject3.accumulate("text","1");

        jsonArray.add(jsonObject3);
        String str = com.alibaba.fastjson.JSONObject.toJSONString(user);
        JSONObject jsonObject=JSONObject.fromObject(str);
        jsonObject.accumulate("telephone",jsonArray);
        jsonObject.accumulate("telephone2",jsonObject3);
        return jsonObject;
    }
}
